package generics;

import java.awt.*;

/**
 * This abstract class represents an object to be drawn/shown in the display. It
 * implements a generic sprite to be drawn with a center, shape and the type.
 * 
 * @author Thomas Marmaduke, jianweigan
 * 
 */
public abstract class AbstractSprite {

	private Point myCenter;
	private Dimension mySize;
	private Color myColor;
	private String myType;

	/**
	 * Construct a shape at the given position, with the given velocity, size,
	 * and color. Also a size for its trail (if implemented).
	 * 
	 * @param center
	 *            position of the shape
	 * @param size
	 *            dimensions of the shape
	 * @param color
	 *            color of the shape
	 */
	public AbstractSprite(Point center, Dimension size, Color color, String type) {
		myCenter = new Point(center.x, center.y);
		mySize = new Dimension(size.width, size.height);
		myColor = color;
		myType = type;
	}

	/**
	 * @return distance from mover to point p
	 */
	public double getDistance(Point p) {
		int dx = p.x - myCenter.x;
		int dy = p.y - myCenter.y;

		return Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2));
	}

	public double getDistance(AbstractSprite othermover) {
		return getDistance(othermover.getCenter());
	}

	/**
	 * Describes how to draw the sprite on the display
	 * 
	 * @param pen
	 *            used to paint shape on the screen
	 */
	public abstract void paint(Graphics pen);

	/**
	 * Reports shape's center.
	 * 
	 * @return center of shape
	 */
	public Point getCenter() {
		return myCenter;
	}

	/**
	 * Reports shape's size.
	 * 
	 * @return size of shape
	 */
	public Dimension getSize() {
		return mySize;
	}

	/**
	 * Changes shape's color.
	 */
	public void setSize(int width, int height) {
		mySize = new Dimension(width, height);
	}

	public void setSize(Dimension d) {
		mySize = d;
	}

	/**
	 * Reports shape's color.
	 * 
	 * @return color of shape
	 */
	public Color getColor() {
		return myColor;
	}

	/**
	 * Changes shape's color.
	 */
	public void setColor(Color c) {
		myColor = c;
	}

	public void setType(String type) {
		myType = type;
	}

	public String getType() {
		return myType;
	}

}
